<!DOCTYPE HTML>
<html style="background: #f3f3f3;" lang="zh-cmn-Hans">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>签约网</title>
    <link rel="stylesheet" type="text/css" href="../css/api.css" />
    <link rel="stylesheet" type="text/css" href="../css/style.css" />
    <link rel="stylesheet" type="text/css" href="../css/lawyer.css" />
    <script type="text/javascript" src="../script/api.js"></script>
    <script type="text/javascript" src="../script/jquery-1.9.1.min.js"></script>
    <script type="text/javascript" src="../script/mobile.js"></script>
    <script type="text/javascript" src="../script/lawyer.js"></script>
</head>
<body>
<div id="secHeader">
  <header class="header">
      <a href="javascript:void(0);" onclick="api.closeWin()" class="back_btn"><img src="../image/head-fanhui.png" alt=""></a>
      <h2>分享奖励</h2>
      <!--<a href="javascript:void (0);" class="search_btn set_btn">设置</a>-->
  </header>
</div>
<section class="money_section">
    <div class="profit">
        <div class="myAward">
            <p>我的奖励金(元)</p>
            <h6 id='reward'>0.00</h6>
            <div class="my_code">
                <span>我的邀请码<em id='idno'>35sdf</em></span>
                <!-- <a href="personal_money_cash.html" class="cash_btn">提现</a> -->
            </div>
        </div>
    </div>
</section>
<section class="other_operation">
    <ul>
        <li><a href="javascript:;" onclick="">邀请律师好友使用签约网 <span class="share_btn">点击分享</span></a></li>
        <li><a href="javascript:;">我的二维码 <span><img src="../image/ewm_code.png" id="ewm"></span></a></li>
        <li><a href="javascript:;">我的邀请码 <span id='idno1'>35sdf</span><input id='idnos' type="text" hidden="hidden"></a></li>
    </ul>
</section>
<section class="other_operation">
    <ul>
        <!-- <li><a href="javascript:;" onclick="aaplay('personal_distribution_profit')">收益明细</a></li> -->
        <li><a href="javascript:;" onclick="aaplay('personal_distribution_invite')">邀请统计</a></li>
    </ul>
</section>
<section class="reminder">
    <h6>活动详情：</h6>
    <p>
        1、点击下载二维码，复制邀请码，邀请好友注册使用app，好友消费后即可获得该单平台服务费的20%作为奖励；<br>
        2、邀请律师好友入驻平台，律师认证成功后我与被邀请的律师都可获得现金奖励。
    </p>
</section>
<section class="code" style="position: absolute; left: 0; top: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.5); z-index: 999;">
    <div class="codeImg" style="position: absolute; left: 0; top: 0; right: 0;
     bottom: 0; margin: auto; width: 5rem; height: 5rem; background: #ffffff;">
        <img src="../image/ewm_code.png" width="100%" height="100%" id="ewm1" style="-webkit-touch-callout:default;">
    </div>
</section>

<div class="fixed_share">
    <div class="fixed_content" style="height:6rem!important;">
        <div class="fixed_title">
            <h6>分享</h6>
        </div>
        <div class="fixed_article">
            <div class="share">
                <ul>
                  <li class="wx">
                      <a onclick="share_wx('session')"><img src="../image/share1.png" alt="">
                          <p>微信好友</p>
                      </a>
                  </li>
                  <li class="wx">
                      <a onclick="share_wx('timeline')"><img src="../image/share2.png" alt="">
                          <p>朋友圈</p>
                      </a>
                  </li>
                  <li class="qq">
                      <a onclick="openqqzoom('QFriend')"><img src="../image/share3.png" alt="">
                          <p>QQ好友</p>
                      </a>
                  </li>
                  <li class="qq">
                      <a onclick="openqqzoom('QZone')"><img src="../image/share4.png" alt="">
                          <p>QQ空间</p>
                      </a>
                  </li>
                  <li class="wb">
                      <a onclick="openwb()"><img src="../image/share5.png" alt="">
                          <p>新浪微博</p>
                      </a>
                  </li>

                  <li>
                      <a onclick="copyUrl()"><img src="../image/share6.png" alt="">
                          <p>复制链接</p>
                      </a>
                  </li>
                </ul>
            </div>
        </div>
    </div>
</div>

</body>

<script>
    var uniqueid='';
    var imgurlType='';
    var imgurl = '';

    $(".code").hide()
    $("#ewm").click(function () {
        $(".code").show()
    })
    $(".code").click(function () {
        $(this).hide();
    })
    $(".codeImg").click(function(e){
        e.stopPropagation;
    })
    var time =0;
      $(".code").on('touchstart', '#ewm1', function(e){
        //e.stopPropagation();
        var imgsrc =imgUrl;
        var imgtypes =imgUrlType.split(".");
        time = setTimeout(function(){
          add(imgsrc,imgtypes[1]);
//           alert('你长按了');
          // alert("图片URL="+imgsrc+"图片类型="+imgtypes[1])
        }, 600);//这里设置长按响应时间
      });

      $(".code").on('touchend', '.code', function(e){
        //e.stopPropagation();
        clearTimeout(time);
      });
    apiready = function () {
      $api.fixStatusBar( $api.dom('#secHeader') );
      api.setStatusBarStyle({
          style: 'light'
      });



        $api.addEvt(document.getElementById('idno1'),'click', function(){
               copy();
        });
        $api.addEvt(document.getElementById('idno'),'click', function(){
               copy();
        });


        if(token!=''){
            user()
        }

        // ios 登录检测是否安装第三方app
         check_qq();
         check_wx();
         check_wb();


    };

    function add(imgurl,imgtypes){
      //alert(imgurl,imgtypes)
      var timestamp = new Date().getTime()
      api.confirm({
        title: '提示',
        msg: "点击确定按钮保存图片到相册",
        buttons: ['确定', '取消']
      }, function(ret, err) {
        var index = ret.buttonIndex;
        if(index == 1){
          api.download({
            url: imgurl,
            savePath: 'fs://test'+timestamp+'.'+imgtypes,
            report: true,
            cache: true,
            allowResume: true,
            networkTypes:"all"
          }, function(ret, err) {
            //alert(JSON.stringify(ret))
            if(ret.state==1){
              api.saveMediaToAlbum({
                path: ret.savePath
              }, function(res, errs) {
                console.log(JSON.stringify(res))
                console.log(JSON.stringify(errs))
                if(res.status ==true){
                  api.toast({
                    msg:'图片已保存到相册'
                  })
                }else{
                  api.toast({
                    msg:'图片保存到相册失败'
                  })
                }
              });
            }

          });
        }else if(index == 2){
          api.toast({
            msg:'取消操作!'
          })
        }

      })

    }

    //复制邀请码
    function copy(){
    	//text为需要复制的文本
      var text=document.getElementById("idnos").value;
      var clipBoard = api.require('clipBoard');
    	clipBoard.set({
       		value: text
    	}, function(ret, err) {
        	if (ret) {
            api.toast({
                msg: '复制成功',
                duration: 2000,
                location: 'bottom'
            });
    		} else {
          api.toast({
              msg: '复制失败',
              duration: 2000,
              location: 'bottom'
          });
        	}
    	});
    }


    function user() {
        var p={token:token,infock:2};
        api.ajax({
            url: webSiteUrl+'/app/user/user',
            method: 'post',
            data: {
                values:p
            }
        }, function(ret, err) {
            console.log(JSON.stringify(ret))
            if(ret.code==200){
                if(ret.data.reward!=''){
                  $("#reward").html(ret.data.reward);
                }
                $("#idno").html(ret.data.idno);
                $("#idno1").html(ret.data.idno);
                $("#idnos").val(ret.data.idno);
                uniqueid = ret.data.idno;
                $("#ewm1").attr('src',webSiteUrl+ret.data.ewm);
                imgUrl = webSiteUrl+ret.data.ewm;
                imgUrlType = ret.data.ewm;

            }else{alert(ret.msg)}
        });
    }

    $(".share_btn").click(function () {
        $(".fixed_share").fadeIn().find(".fixed_content").animate({
            'top':'0',
            'opacity':'1'
        },400)
    });
    $(".fixed_content").click(function (e) {
        e.stopPropagation();
    });
    $(".share ul li").click(function () {
        $(".fixed_share").fadeOut().find(".fixed_content").animate({
            'top':'4rem',
            'opacity':'0'
        },400)
    });
    //关闭分享
    $(".fixed_share").click(function (e) {
        e.stopPropagation();
        $(".fixed_share").fadeOut().find(".fixed_content").animate({
            'top':'4rem',
            'opacity':'0'
        },400)
    });

    //分享到微信
    function share_wx(wx_scene){//wx_scene,取值范围：session（会话）timeline（朋友圈）favorite（收藏）

        var wx = api.require('wx');
        wx.isInstalled(function(ret, err){
            if(ret.installed){
                //alert("当前设备已安装微信客户端");
                wx.shareWebpage({
                    scene: wx_scene,
                    title: '邀请好友注册',
                    description: '您的好友邀请您共同体验签约网的便民法律服务',
                    thumb: 'widget://login.jpg',
                    contentUrl: webSiteUrl+'/Home/Lawyer/register.html?uniqueid='+uniqueid,
                }, function(ret, err){

                });


            }else{
                alert('当前设备未安装微信客户端，请安装微信后再分享。');
            }
        });
    }


        //分享到QQ
    function openqqzoom(type) {

        var qq = api.require('qq');
        qq.installed(function(ret, err) {
                if (ret.status) {
                    qq.shareNews({
                        url : webSiteUrl+'/Home/Lawyer/register.html?uniqueid='+uniqueid,
                        title: '邀请好友注册',
                        description: '您的好友邀请您共同体验签约网的便民法律服务',
                        thumb: 'widget://login.jpg',
                        type:type        //  QFriend
                    }, function(ret, err) {
                        if (ret.status) {

                        }

                    });
                } else {
                    api.toast({
                        msg : '当前设备未安装QQ客户端'
                    });

                }
        });
    }


    //分享微博
    function openwb(){
        var id = api.pageParam.id;
        var weibo = api.require('weibo');
        weibo.isInstalled(function(ret) {
            if (ret.status) {
                weibo.shareWebPage({
                  title: '邀请好友注册',
                  description: '您的好友邀请您共同体验签约网的便民法律服务',
                    thumb: 'widget://login.jpg',
                    contentUrl: webSiteUrl+'/Home/Lawyer/register.html?uniqueid='+uniqueid,
                }, function(ret, err) {
                    if (ret.status) {

                    }
                });
            } else {
                alert('未安装新浪微博客户端');
            }
        });
    }

    //复制
     function copyUrl(){
        var clipBoard = api.require('clipBoard');
        clipBoard.set({
            value: webSiteUrl+'/Home/Lawyer/register.html?uniqueid='+uniqueid,
        }, function(ret, err) {
            if (ret) {
              api.toast({
                  msg: '复制成功',
                  duration: 2000,
                  location: 'bottom'
              });
            }else {
              api.toast({
                  msg: '复制失败',
                  duration: 2000,
                  location: 'bottom'
              });
            }
        });
    }


</script>
</html>
